<template>
	<view class="container">
		<!-- 提现资金 -->
		<view class="paywayItem">
			<view class="">
				<text>请输入好友会员ID或者手机号</text>
				<view class="" style="width: 670rpx;margin-top: 30rpx;">
					<u-search placeholder="请输入" v-model='memberCode' bgColor='#ffffff' borderColor='#eeeeee' @custom="memberCodeSearch" @search="memberCodeSearch"></u-search>
				</view>
				<u-cell-group :border='false' title='确认信息' style='margin-top: 40rpx;' border v-if='memberInfo.id'>
					<u-cell title="会员昵称" :value='memberInfo.nickname' :border='false' v-if='memberInfo.nickname'></u-cell>
					<u-cell title="会员级别" :value='memberInfo.rankModel.rankName' :border='false' v-if='memberInfo.rankModel.rankName'></u-cell>
					<u-cell title="会员ID" :value='memberInfo.code' :border='false'></u-cell>
					<u-cell title="会员手机号" :value='memberInfo.phone' :border='false' v-if='memberCode.length>=11'></u-cell>
				</u-cell-group>
			</view>
			
		</view>
		<!-- 提现金额 -->
		<view class="confirmPayMoney" v-if='memberInfo.id'>
			<text style="font-size: 24rpx;color: #666666;margin-bottom: 20rpx;">可赠金币{{userInfo.golds}}</text>
			<text class="title">赠送金额</text>
			<view class="input_con">
				<text>¥</text>
				<input type="digit" :value="totalPrice" @input="payMoneyChange" placeholder="请输入赠送金额" placeholder-style="font-size: 28rpx" maxlength='8' confirm-type='done'/>
			</view>
			<text style="color: red;font-size: 26rpx;" v-if="!totalPricePass">{{priceRule}}</text>
		</view>
		<view class="message" v-if='memberInfo.id'>
			<!-- <text style="color: #d4a781;" >系统会优先赠送专项积分，一旦赠送，不可退回</text> -->
		</view>
		<!-- 提现按钮 -->
		<view class="confirm" v-if='memberInfo.id'>
			<jc-button @click='confirmTap' style="margin-top: 100rpx" :width='690' title='确认赠送' backgroundColor="#d4a781"></jc-button>
		</view>
		
	</view>
</template>

<script>
	import {user} from '@/api/user.js'
	import {order} from '@/api/order.js'
	import {payway} from '@/api/payway.js'
	export default{
		data() {
			return {
				memberInfo: {},
				userInfo:{},
				totalPrice: '',
				totalPricePass: true,
				priceRule: "请输入大于零的数字",
				lastItem:{},
				paywayInfo: {},
				memberCode: '',
				typeList: [
					{
						name: '支付宝',
						key: 'ali'
					},{
						name: '微信',
						key: 'wx'
					},{
						name: '银行卡',
						key: 'bank'
					}]
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.getUserInfo()
		},
		onPullDownRefresh() {
			this.getUserInfo()
		},
		methods:{
			getUserInfo() {
				user.getUserInfo().then(res => {
					uni.stopPullDownRefresh()
					if (res.data.code == 10000) {
						var userInfo = res.data.data
						userInfo.incomesPass = this.$count.add(userInfo.incomes, userInfo.incomesLocked)
						userInfo.bankInfo = userInfo.bankName + ' ' + userInfo.bankAccount
						this.userInfo = userInfo
					}
				})
			},
			memberCodeSearch(e){
				if(!e){
					this.$show.showMessage('请输入会员ID')
					this.memberInfo={}
					return
				}
				console.log('搜索', e)
				user.getUserInfoByCode({
					memberCode: e
				}).then(res=>{
					if(res.data.code==10000){
						this.memberInfo = res.data.data
					}else{
						this.memberInfo={}
					}
				})
			},
			//完善会员资料
			setMemberInfo(){
				this.$Router.push({
					name: 'updateBankInfo'
				})
			},
			//选择到账卡
			selecttOutMoneyCart(){
				
			},
			//确认提现金额
			payMoneyChange(e){
				var value = e.detail.value.replace(/\s/g, "")
				if(isNaN(value)){
					this.totalPricePass = false
				}else{
					this.totalPricePass = true
				}
				if(value){
					this.totalPrice = parseFloat(value)
				}else{
					this.totalPrice = 0
				}
			},
			//确认提现按钮
			confirmTap(){
				if(!this.memberInfo.code){
					this.$show.showMessage('请选择会员ID')
					return
				}
				if(!this.totalPrice){
					this.$show.showMessage('请输入合法金额')
					return
				}
				console.log('发送')
				var that = this
				uni.showModal({
					content: "一旦赠送，不可退回，确认赠送？",
					confirmText: "确定",
					cancelText: '取消',
					success(res_) {
						console.log(res_)
						if(res_.confirm){
							that.updateUserForSendGolds()
						}
					}
				})
				
			},
			//赠送
			updateUserForSendGolds(){
				user.updateUserForSendGolds({
					userId: this.memberInfo.id,
					money: this.totalPrice
				}).then(res => {
					if(res.data.code == 10000){
						uni.showModal({
							title: "赠送成功",
							confirmText: "确定",
							showCancel: false,
							success(res_) {
								if(res_.confirm){
									uni.navigateBack({
										
									})
								}
							}
						})
					}else if(res.data.code == 10001){
						this.$show.showMessage(res.data.data)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container{
	}
	.paywayItem{
		margin-top: 20rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		background-color: #FFFFFF;
		padding: 30rpx;
	}
	.payway_cont{
		background-color: #FFFFFF;
		margin-top: 30rpx;
		.content_item{
			display: flex;
			flex-direction: row;
			align-items: center;
			padding: 0 30px;
			.left{
				.isSelect{
					width: 36rpx;
					height: 36rpx;
					padding: 10rpx;
				}
			}
			.right{
				width: 100%;
				display: flex;
				flex-direction: column;
				margin-left: 20rpx;
				padding: 30rpx 0;
			}
			.bottomLine{
				border-bottom: 1px solid #EFEFEF
			}
		}
	}
	.confirmPayMoney{
		margin-top: 20rpx;
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		background-color: #FFFFFF;
		.title{
			font-size: 32rpx;
		}
		.input_con{
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 40rpx;
			// border-bottom: 1px #EFEFEF solid;
			text{
				margin-right: 20rpx;
				font-size: 44rpx;
				font-weight: bold;
			}
			input{
				width: 100%;
				font-size: 34rpx;
			}
		}
		text{
			
		}
	}
	.message{
		color: $st-color-primary;
		font-size: 22rpx;
		margin-top: 20rpx;
		padding: 0 20rpx;
	}
	.confirm{
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>
